package com.fc.authentication.modules.product.rs;

import com.fc.authentication.common.dto.Result;
import com.fc.authentication.modules.product.domain.Product;
import com.fc.authentication.modules.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Sunny on 2018/6/29.
 */
@RestController
@RequestMapping("/api/product")
public class ProductResource {

    @Autowired
    private ProductService productService;


    @GetMapping("/list")
    public Result list(@PageableDefault(sort = {"prodCode"}, direction = Sort.Direction.DESC) Pageable pageable)
    {
        Page<Product> productsPage = productService.findAllProducts(pageable);
        return Result.ok(productsPage);
    }
}
